package com.gosophia.metadataEngine.service.impl.test.integration;


import java.util.List;
import java.util.UUID;

import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.test.context.transaction.TransactionConfiguration;

import com.gosophia.commons.exception.BusinessException;
import com.gosophia.commons.exception.ConcurrencyException;
import com.gosophia.metadataEngine.dao.MetaDataFiledDao;
import com.gosophia.metadataEngine.dao.MetaDataTableDao;
import com.gosophia.metadataEngine.entity.DataSourceInfo;
import com.gosophia.metadataEngine.entity.MetaDataField;
import com.gosophia.metadataEngine.entity.MetaDataTable;
import com.gosophia.metadataEngine.service.MetaDataFieldService;
/**
 * MetaDataFieldService集成测试
 * @author mayue
 *
 */
@ContextConfiguration(locations = { "classpath:applicationContext-it.xml",
"classpath*:moduleContext.xml" })
@TransactionConfiguration(defaultRollback=true)
public class ITMetaDataFieldServiceImpl extends
                    AbstractTransactionalJUnit4SpringContextTests{
    @Autowired
    private MetaDataFieldService metaDataFieldService;
    @Autowired
    private MetaDataFiledDao metaDataFiledDao;
    
    @Autowired
    private MetaDataTableDao metaDataTableDao;
    
    @Test
    public void testFindSystemFieldByTableId() throws BusinessException{
        List<MetaDataField> list = metaDataFieldService.findSystemFieldByTableId(6L);
        Assert.assertEquals(5, list.size());
        for(MetaDataField m:list){
            System.out.println("字段名:"+m.getColName() +"字段长度:"+m.getColWidth()+" 字段类型:"+m.getFieldType()+" 是否主键:" + m.getIsPk());
        }
    }
    @Test
    public void testFindSystemFieldByTableIdNoSourceInfo() throws BusinessException{
        List<MetaDataField> list = metaDataFieldService.findSystemFieldByTableId(6L);
        Assert.assertEquals(5, list.size());
    }
    @Test(expected = BusinessException.class)
    public void testFindSystemFieldByTableIdNoTable() throws BusinessException{
        metaDataFieldService.findSystemFieldByTableId(3L);
    }
    @Test
    public void testFindMetaDataFieldByTableIdListShowNoHidden(){
        List<MetaDataField> list = metaDataFieldService.findMetaDataFieldByTableIdListShow(6L);
        Assert.assertEquals(5, list.size());
    }
    
    @Test
    public void testFindMetaDataFieldByTableId(){
        List<MetaDataField> list = metaDataFieldService.findMetaDataFieldByTableId(6L);
        Assert.assertEquals(5, list.size());
        for(MetaDataField m:list){
            System.out.println(m.getColName()+"--排序号："+m.getFieldOrder());
        }
        
    }
    @Test
    public void testRemoveMetaDataField(){
        metaDataFieldService.removeMetaDataField(6L, 0L);
    }
    @Test(expected=ConcurrencyException.class)
    public void testRemoveMetaDataFieldNoId(){
        metaDataFieldService.removeMetaDataField(1000L, 0L);
    }
    
   
}
